﻿@model Springwater.Business.ViewModels.SearchPanelModel

<table id="searchTable">
    <tbody>
        <tr>
            <td>Kod:</td>
            <td>@Html.TextBox("tbxKod")</td>
        </tr>
        <tr>
            <td>Nev:</td>
            <td>@Html.TextBox("tbxNev")</td>
        </tr>
        <tr>
            <td>Tajegyseg:</td>
            <td>@Html.DropDownList("ddlTajegyseg", Model.TajegysegDLL)</td>
        </tr>
        <tr>
            <td>Vizgyujto:</td>
            <td>@Html.DropDownList("ddlVizgyujto", Model.VizgyujtoDLL)</td>
        </tr>
    </tbody>
</table>
<table id="dataTable">
    <thead>
        <tr>
            <th>Id</th>
            <th>Kod</th>
            <th>Nev</th>
            <th>Tajegyseg</th>
            <th>Vizgyujto</th>
            <th>Eredet</th>
            <th>Allapot</th>
            <th>Forma</th>
            <th>Kiepitettseg</th>
        </tr>
    </thead>
    <tbody>
    </tbody>
</table>

<script type="text/javascript" >
    var oTable = null;

    $(document).ready(function () {

        var url = '@Url.Action("Index", "Borviz", new { id = "_ID_" })';

        oTable = $('#dataTable').dataTable({
            "bPaginate": true,
            "bSort": true,
            "bServerSide": true,
            "sAjaxSource": "@Url.Action("Search", "Borviz")",
            "sServerMethod": "POST",
            "sDom": 'rtip',
            "aoColumns": [
                            {"sName": "Id", "bVisible" : false},
                            {
                                "sName": "Kod",
                                "bSearchable": false
                                //"bSortable": true,
                                //"fnRender": function (oObj) {
                                //    return '<a href=\"Details/' +
                                //    oObj.aData[0] + '\">View</a>';
                                //}
                            },
                            {
                                "sName": "Nev",
                                "bSortable": true,
                                "fnRender": function (oObj) {
                                    return '<a href="' + url.replace("_ID_", oObj.aData[0]) + '">' + oObj.aData[2] + '</a>';
                                }
                            },
                            { "sName": "Tajegyseg", "bSortable": true },
                            { "sName": "Vizgyujto" },
                            { "sName": "Eredet" },
                            { "sName": "Allapot" },
                            { "sName": "Forma" },
                            { "sName": "Kiepitettseg" }

            ],
            "fnServerParams": SetServerParams
        });

        BindEvents();

    });

    function BindEvents() {
        $("#searchTable input").keyup(function () { Redraw(); });
        $("#searchTable select").change(function () { Redraw(); });
    }

    function SetServerParams(aoData) {
        aoData.push({ "name": "Kod", "value": $("[name=tbxKod]").val() });
        aoData.push({ "name": "Nev", "value": $("[name=tbxNev]").val() });
        aoData.push({ "name": "Tajegyseg", "value": $("[name=ddlTajegyseg]").val() });
        aoData.push({ "name": "Vizgyujto", "value": $("[name=ddlVizgyujto]").val() });
    }

    function Redraw() {
        oTable.fnFilter();
    }
</script>